####
#### Eroll Kuhn & Rahsaan Maxwell
#### Predictions
#### 10.2020


rm(list=ls())

library(tidyverse)
library(gridExtra)

# read in frame
df <- read.csv(".../4a.Predicted Values/Output/B.Tables/CleanPredictions_forPlot_v2.csv")


df$facet_lab <- ifelse(df$Var=="% Foreign-Born",1,
                       ifelse(df$Var=="% Non-EU Foreign-Born",2,
                                     ifelse(df$Var=="% Co-National (Syrians Only)",3,NA)))



df$facet_lab <- factor(df$facet_lab,
                       levels = c(1,2,3),
                       labels = c("% Foreign-Born", 
                                  "% Non-EU Foreign-Born",
                                  "% Co-National (Syrians Only)"))


setwd(".../4a.Predicted Values/Output/D.Figures")
png("Dem_Predictions.png",
    width=10,height=6,units='in',res=300)
ggplot(df) +
  geom_line(aes(x=Value,y=Pred),size=1) +
  geom_smooth(aes(x=Value,y=bottom95),color="red",size=0.5,lty=3) +
  geom_smooth(aes(x=Value,y=top95),color="red",size=0.5,lty=3) +
  geom_col(aes(x=Value,y=prop_val)) +
  facet_wrap(~facet_lab) +
  theme_bw() + 
  geom_hline(yintercept = 0, lty = 2) +
  geom_hline(yintercept = 1, lty = 2) +
  ylim(-0.05,1.20) +
  xlab("Value of Demographic Variable (% of County Population)") +
  ylab("Predicted Value on Welcomeness Index") +
  theme(legend.position = "none",
        panel.grid.major.x = element_blank(),
        panel.grid.minor = element_blank(),
        panel.grid.major = element_blank())
dev.off()

